$(function () {
    $("li.flexLi").click(function () {
        $("li.flexLi").removeClass("actives")
        $(this).addClass("actives");
    });
    $("ul.ulFlex>li").eq(0).click()
});


//点击加载影像
function uploadAdd(types) {
    var reservationsId= document.getElementById("reservationsId").value;
    var customerId= document.getElementById("customerId").value;
    var iconType = types.innerHTML;
    var cri = customerId + "," + reservationsId + "," + iconType;
    $.ajax({
        type: "POST",
        url: Feng.ctxPath + "/doctorLooked/getIconInfo/"+cri,
        data: {},
        dataType: "json",
        success: function (data) {
            $("#contentBoxs").html("");
            var obj = {};
            for(var i=0;i<data.length;i++){
                if(obj.hasOwnProperty(data[i].payServiceName)){
                    obj[data[i].payServiceName].push(data[i])
                }else {
                    obj[data[i].payServiceName] = [];
                    obj[data[i].payServiceName].push(data[i])
                }
            }
            for(var item in obj){
                var timet= (obj[item][0].diagnoseTime).substring(0,10);
                var timecontainer = $("<div id='"+obj[item][0].diagnoseTime+"' style='box-shadow: 2px 2px 2px #cccccc;margin-top: 20px;padding: 0 0 20px;border-radius: 5px;'>" +
                    "<p style='background: #337ab7;color: white;text-indent: 1em;line-height: 40px;'><span>"+obj[item][0].payServiceName+"</span></p></div>");
                $("#contentBoxs").append(timecontainer);
                   for(var w = 0; w < obj[item].length;w ++){
                    var img = $(" " +
                        "<span style='display:inline-block;width: 300px;border: 1px solid #cccccc;margin-left: 20px;position: relative'>" +
                        "<a style='width: 150px;margin:0 74px 0;' href='javascript:;' class='thumbnail'>" +
                        "<img class='layui-upload-img' onclick='previewImg(this)' src='"+obj[item][w].imageUrl+"' alt=''></a>" +
                        "<span style='size: 8px'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+timet+"</span>" +
                        "<button onclick='imgDel("+obj[item][w].id+")' class='btn btn-xs btn-default' type='button' style='z-index: 9;position: absolute;bottom: 5px;right: 15px;background:white;color: #333333;'>" +
                        "<span class='glyphicon glyphicon-trash spanmis' ></span></button></span>")
                    timecontainer.append(img)
                }
            }
        }
    });
}

function previewImg(obj) {
    var img = new Image();
    img.src = obj.src;
    var height = img.height + 50; //获取图片高度
    var width = img.width; //获取图片宽度
    var imgHtml = "<img src='" + obj.src + "' />";
    //弹出层
    layer.open({
        type: 1,
        shade: 0.8,
        offset: 'auto',
        area: [width +'px',height+'px'],
        shadeClose:true,//点击外围关闭弹窗
        scrollbar: false,//不现实滚动条
        title: "图片预览", //不显示标题
        content: imgHtml, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
        cancel: function () {
            //layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', { time: 5000, icon: 6 });
        }
    });
}

function imgDel(id) {
    if(confirm("确定删除图片?")) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/imgDel",
            type: "post",
            data: {
                id: id
            },
            success: function (data) {
                Feng.success('操作成功!');
                location.reload();
            },
            error: function (data) {
                alert('内部故障!');
            }
        });
    }
}

//打开上传影像
function openIconType(){
    var reservationsId= document.getElementById("reservationsId").value;
    var customerId= document.getElementById("customerId").value;
    var cri=reservationsId+","+customerId;
    var index = layer.open({
        type: 2,
        title: '请关联预约',
        area: ['30%', '55%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/openIconType/'+cri
    });
    this.layerIndex = index;

}

//上传影像
function uploadicon(){
    var payServiceId= document.getElementById("payServiceId").value;
    var iconType= document.getElementById("iconType").value;
    var remarks= document.getElementById("remarks").value;
    if(iconType=='请选择' || remarks==null ){
        alert("请选择上传图片类型或填写备注!");
    }else{
        var avatarUp = new $IconUpload("avatar");
        avatarUp.setIconUploadBarId("progressBar");
        avatarUp.initIcon();
    }
}



